package com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.blog;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.IIdentifyable;
import com.googlecode.hmvc4gwt.example.hmvcblog.server.domain.user.User;

@Entity
@NamedQueries({
	@NamedQuery(name="Blog.findByName", query="SELECT blog FROM Blog blog WHERE blog.title=?1"),
	@NamedQuery(name="Blog.getAll", query="FROM Blog blog"),
	@NamedQuery(name="Blog.blogsOfUser", query="SELECT blog FROM Blog blog WHERE blog.user=?1")
})
public class Blog implements IIdentifyable {
	
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	private int id;

	private List<BlogEntry> blogEntry;

	private User user;
	
	private String description;

	private String title;
	
	private Date dateLastUpdate;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false)
	public Date getDateLastUpdate() {
		return dateLastUpdate;
	}

	@Column(length=10000)
	public String getDescription() {
		return description;
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}

	@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, mappedBy="blog")
	public List<BlogEntry> getBlogEntry() {
		return blogEntry;
	}

	@Column(nullable=false)
	public String getTitle() {
		return title;
	}

	@ManyToOne(optional=false)
	public User getUser() {
		return user;
	}

	public void setDateLastUpdate(Date dateLastUpdate) {
		this.dateLastUpdate = dateLastUpdate;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setBlogEntry(List<BlogEntry> blogEntry) {
		this.blogEntry = blogEntry;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
